package com.林子祺.CAT旅游系统.view.tour.buy;

import com.林子祺.CAT旅游系统.entity.ticket.CurrentTicketData;
import com.林子祺.CAT旅游系统.entity.ticket.TicketData;
import com.林子祺.CAT旅游系统.entity.ticketbuy.BuyData;
import com.林子祺.CAT旅游系统.entity.ticketbuy.CurrentBuyData;
import com.林子祺.CAT旅游系统.view.Menu;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TicketBuyAns {

    static int number = 0;
    static int t = 1;

    public static void show() {
        JFrame jf = new JFrame("门票查询");
        jf.setSize(700, 400);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        // 创建内容面板，使用边界布局
        JPanel panel = new JPanel(new BorderLayout());

        // 表头（列名）
        Object[] columnNames = {"订票id", "用户", "购买的门票", "购买时间"};

        // 表格所有行数据
        Object[][] rowData = {
                {"订票id", "用户", "购买的门票", "购买时间"},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
        };

        // 创建一个表格，指定 所有行数据 和 表头
        JTable table = new JTable(rowData, columnNames);
        table.setLocation(0,0);
        table.setSize(400,120);

        while (BuyData.OutputData(number)) {
            table.getModel().setValueAt(CurrentBuyData.order_id, t, 0);
            table.getModel().setValueAt(CurrentBuyData.costumer, t, 1);
            table.getModel().setValueAt(CurrentBuyData.TicketBought, t, 2);
            table.getModel().setValueAt(CurrentBuyData.Buytime, t, 3);
            number++;
            t++;
        }
        number = t = 0;


        // 把 表头 添加到容器顶部（使用普通的中间容器添加表格时，表头 和 内容 需要分开添加）
        panel.add(table.getTableHeader(), BorderLayout.NORTH);
        // 把 表格内容 添加到容器中心
        panel.add(table, BorderLayout.NORTH);

        JButton btn2 = new JButton("返回");
        panel.add(btn2, BorderLayout.SOUTH);
        btn2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    Menu.menu();
                } catch (AWTException awtException) {
                    awtException.printStackTrace();
                }
                jf.dispose();
            }
        });

        jf.setContentPane(panel);
        jf.pack();
        jf.add(btn2);
        jf.setLocationRelativeTo(null);
        jf.setVisible(true);

    }
}
